package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.BillElecDAO;
import guda.house.dal.dataobject.BillElecDO;
import guda.grape.autogen.common.page.BaseQuery;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BillElecDAOImpl extends BaseDAO implements BillElecDAO {

    @Override
	public Long insert(BillElecDO billElec) {
	      try {
                return (Long) getSqlMapperW().insert("bill_elec.insert",billElec);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public BillElecDO getBillElecById(Long recordId) {
	    return (BillElecDO)getSqlMapClientTemplate().queryForObject("bill_elec.getBillElecById", recordId);
	}

    @Override
	public boolean delBillElecById(Long recordId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("bill_elec.delBillElecById",recordId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<BillElecDO> getBillElecByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("bill_elec.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long recordId) {
	    try {
            getSqlMapperW().update("bill_elec.cleanAutoIncrement",recordId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<BillElecDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_elec.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_elec.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(BillElecDO billElec) {
        try {
            getSqlMapperW().update("bill_elec.updateByIdSelective",billElec);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<BillElecDO> getBill(Long suiteId, Integer recordYear, Integer recordMonth) {
        Map m = new HashMap();
        m.put("suiteId",suiteId);
        m.put("recordYear",recordYear);
        m.put("recordMonth",recordMonth);
        return getSqlMapClientTemplate().queryForList("bill_elec.getBill", m);
    }

    @Override
    public List<BillElecDO> selectForUnpay(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_elec.selectForUnpay", baseQuery);
    }

    @Override
    public int countForUnpay(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_elec.countForUnpay",baseQuery);
    }

    @Override
    public Long statBill(List<Long> suitIdList, String gmtDate, Integer isPayed) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtDate",gmtDate);
        m.put("isPayed",isPayed);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_elec.statBill", m);
    }

    @Override
    public Long statBillRate(List<Long> suitIdList, String gmtStart, String gmtEnd, Integer isPayed) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtStart",gmtStart);
        m.put("gmtEnd",gmtEnd);
        m.put("isPayed",isPayed);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_elec.statBillRate", m);
    }

    @Override
    public List<BillElecDO> getByPayId(Long payId) {
        return getSqlMapClientTemplate().queryForList("bill_elec.getByPayId", payId);
    }

    @Override
    public BillElecDO queryLatest(Long suiteId) {
        return (BillElecDO)getSqlMapClientTemplate().queryForObject("bill_elec.queryLatest",suiteId);
    }

    @Override
    public Long statDichanDiscount(List<Long> suiteIdList, String gmtDate) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("gmtDate",gmtDate);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_elec.statDichanDiscount", m);
    }

    @Override
    public Long statSelfDiscount(List<Long> suiteIdList, String gmtDate) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("gmtDate",gmtDate);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_elec.statSelfDiscount", m);
    }

    @Override
    public List<BillElecDO> statLastBill(List<Long> suiteIdList, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("isPayed",isPayed);
        return getSqlMapClientTemplate().queryForList("bill_elec.statLastBill", m);
    }

    @Override
    public List<BillElecDO> getBillList(List<Long> suiteIdList, Date gmtStart, Date gmtEnd, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("startDate",gmtStart);
        m.put("endDate",gmtEnd);
        m.put("isPayed",isPayed);
        return getSqlMapClientTemplate().queryForList("bill_elec.getBillList", m);
    }

    @Override
    public List<BillElecDO> getBillByYear(List<Long> suiteIdList, Integer recordYear, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("recordYear",recordYear);
        m.put("isPayed",isPayed);
        return getSqlMapClientTemplate().queryForList("bill_elec.getBillByYear", m);
    }

    @Override
    public Long statBillByYear(List<Long> suiteIdList, Integer year, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("recordYear",year);
        m.put("isPayed",isPayed);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_elec.statBillByYear", m);
    }

    @Override
    public Long statPaidBill(List<Long> billIdList) {
        Map m = new HashMap();
        m.put("billIdList",billIdList);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_elec.statPaidBill", m);
    }


}

